<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>开屏广告编辑</title>
<#include "/WEB-INF/content/module-edit.html">
<link href="${request.contextPath}/res/kindeditor/themes/default/default.css" rel="stylesheet" />
<script charset="utf-8" src="${request.contextPath}/res/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="${request.contextPath}/res/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript">
var sysStatus = [
    {"id":"0","text":"不可用"},
    {"id":"1","text":"可用"}
];
var isRecommand = [
    {"id":"0","text":"不推荐"},
    {"id":"1","text":"推荐"}
];
var oper=[
	{"id":"0","text":"富文本"},
	{"id":"1","text":"连接"}
];
var imgType=[
	{"id":"small","text":"小图"},
	{"id":"middle","text":"中图"},
	{"id":"big","text":"大图"}
];
KindEditor.ready(function(K) {
    window.editor = K.create('#mas', {
        langType : 'zh_CN',
        height:"400px",
        uploadJson : '${request.contextPath}/res/kindeditor/jsp/upload_json_textarea.jsp',
        fileManagerJson : '${request.contextPath}/res/kindeditor/jsp/file_manager_json.jsp',
        allowFileManager :false,
        items:['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
               'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
               'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
               'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
               'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
               'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'table', 'hr', 'baidumap', 'pagebreak',
               'anchor', 'link', 'unlink', '|', 'about'
       ],themeType : 'simple',
       });
});
$(function() {
	<#if object.contentType??>
	<#if object.contentType=='1'>
		$("#pi").show();
		$("#pt").hide();
	<#else>
		$("#pi").hide();
		$("#pt").show();
	</#if>
	<#else>
		$("#pi").hide();
		$("#pt").show();
	</#if>
  	$("#isRecommand").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
  		data:isRecommand
  	}); 
  	$("#status").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
  		data:sysStatus
  	}); 
  	$("#imgType").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
  		data:imgType
  	}); 
  	$("#contentType").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
  		data:oper,
  		onChange:function(data){
  			if(data==1){
  				$("#pi").show();
  				$("#pt").hide();
  			}else{
  				if(data==0){
  	  				$("#pi").hide();
  	  				$("#pt").show();
  				}
  			}
  		}
  	});
  	
  	$("#imgUrl").validatebox({
  		required:true
  	});
  	
  	init();
 });
 
 
 
	function init(){
		loadPlug();
	}
	 function sub(){
		/* var width=${map.width!0};
		var height=${map.height!0};
		if (!$("#form").form('validate'))
			return;
		if(width != 0 && height != 0){
			if($("#width").val()==width){
				if($("#height").val()==height){
				}else{
					top.showMsg("图片高度不等于"+height+"像素");
					return;
				}
			}else{
				top.showMsg("图片宽度不等于"+width+"像素");
				return;
			}
		} */
		mySave(); 
	}
	 
	 function loadPlug(){
		$("#upload").click(function(){
	 		editor.loadPlugin('image', function() {
	 			editor.plugin.imageDialog({
	 				showRemote:false,
	 				imageUrl : $('#imgUrl').val(), //如果图片路径框内有内容直接赋值于弹出框的图片地址文本框
	 				//点击弹窗内”确定“按钮所执行的逻辑
	 				clickFn : function(url, title, width, height, border, align) {//经过处理返回的Url是图片地址,width宽度，height高度,align是图片尺寸
	 					$("#width").val(width);
	 					$("#height").val(height);
	 					$('#imgUrl').val(url);//获取图片地址
		 				$("#show").attr("src","${map.imgPath!}"+url);
	 					editor.hideDialog(); //隐藏弹窗
	 				}
	 			});
			});	
		});
	}
 
 
 
 
 function mySave(){
	 var i=$("#contentType").combobox("getValue");
	 if(i=='1'){
		 $("#url").attr("name","content");
	 }else
		 if(i=='0'){
			 $("#mas").attr("name","content");
			 var head="<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><title></title><meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no\" /><script type=\"text/javascript\">"+
			 "document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + 'px';"+
			 "<\/script><style type=\"text/css\">*{margin: 0;padding: 0;}img{width: 100%;padding-bottom: 0.4rem;}"+
			 "html{font-size: 0.24rem;font-family: sans-serif;line-height: 1.7rem;color: #787878;}@media screen and (max-width: 321px) {body {font-size:0.24rem;padding: 0.2rem;text-align: justify;}}@media screen and (min-width: 321px) and (max-width:400px) {body {font-size:0.28rem;padding: 0.2rem;text-align: justify;}}@media screen and (min-width: 400px) {body {font-size:0.30rem;padding: 0.2rem;text-align: justify;}}</style></head><body>";
			 var tail="</body></html>";
			 var value=$("#mas").val();
			 if(value.indexOf("<!DOCTYPE")==-1){
				 $("#mas").val(head+value+tail);
			 }
		 }
	 save();
 }
</script>
<style>
.input-width{
	width: 95%;
}
</style>
 
</head>
<body class="easyui-layout">
	<div region="north" id="toolbar" style="background-color: #eee; padding: 5px; overflow: hidden;" border="false">
		<#if object.id?exists&&object.id!="">
			<@auth code="activity:column:update">
				<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-add" style="border: 1px solid #ccc" onclick="javascript:sub()">保存</a>
			</@auth>
		<#else>
			<@auth code="activity:column:create">
				<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-add" style="border: 1px solid #ccc" onclick="javascript:sub()">保存</a>
			</@auth>
		</#if>
		<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-edit" style="border: 1px solid #ccc" onclick="javascript:cancel()">关闭</a>
	</div>
	<div region="center">
		<div id="p" class="easyui-panel" style="background: #fafafa; padding: 10px" fit="true" toolbar="#toolbar">
			<form id="form" method="post">
			<input id="_id" type="hidden" name="id" value="${(object.id)!}">
				<table class="form" cellspacing="0" style="width: 100%">
					<tbody style="border: 1px solid #ccc">
						<tr>
							<td class="label">栏目名称：</td>
							<td><input id="title" name="title" style="width:90%;" required="true" value="${object.title!}" class="easyui-validatebox" required="true"/></td>
							<td class="validate">*</td>									
							<td class="label">位置：</td>
							<td><input class="easyui-combobox" data-options=" valueField:'id',textField:'name',url:'${request.contextPath}/activity/columnType/getTypeList'"  id="typeId" name="typeId" value="${(object.typeId)!}" required="true"/></td>
							<td class="validate">*</td>		
						</tr>							
						<tr>
							<td class="label">栏目副标题:</td>
							<td>
								<input id="subTitle" name="subTitle" class="easyui-validatebox" style="width:90%;" required="true" value="${(object.subTitle)!}"/>
							</td>
							<td class="validate">*</td>
							<td class="label">展示顺序:</td>
							<td><input id="showOrder" name="showOrder" value="${object.showOrder!0}"/></td>
						</tr>
						<tr>
							<td class="label">状态：</td>
							<td><input id="status" name="status" required="true" value="${object.status!'1'}" /></td>
							<td class="validate"></td>							
							<td class="label">内容类型：</td>
							<td><input id="contentType" name="contentType" required="true" value="${object.contentType!'0'}" /></td>
							<td class="validate"></td>								
						</tr>
						<tr>
							<td class="label">是否推荐：</td>
							<td><input id="isRecommand" name="isRecommand" required="true" value="${object.isRecommand!'1'}" /></td>
							<td class="validate"></td>
							<td class="label">图片大小：</td>
							<td><input id="imgType" name="imgType" required="true" value="${object.imgType!'small'}" /></td>
							<td class="validate"></td>		
						</tr>
						<tr style="height:230px;">
							<td class="label"> 推荐图片上传:</td>
							<td>
								<a href="#" class="easyui-linkbutton" id="upload" style="margin-left:200px;">开始上传</a>
								<input id="width" type="hidden"/><input id="height" type="hidden"/>
							</td>
							<td class="validate">*</td>
							<td class="label">展示图预览:</td>
							<td>
								<img src="${map.imgPath!}${(object.imgUrl)!}" style="width:100%;height:200px;" id="show"/>
								<input class="easyui-validatebox" required="true" value="${(object.imgUrl)!}" id="imgUrl" name="imgUrl" style="width:90%;" readonly="readonly"/>
							</td>
							<td class="validate">*</td>								
						</tr>
						<tr id="pi">
							<td class="label">内容：</td>
							<td colspan="4"><input id="url" style="width:90%;" value="<#if object.contentType=='1'>${object.content!}</#if>"/></td>
							<td class="validate"></td>
						</tr>
						<tr id="pt">
							<td class="label">内容：</td>
							<td colspan="4"><textarea id="mas" style="width:90%;"><#if object.contentType=='0'>${object.content!}</#if></textarea></td>
							<td class="validate"></td>
						</tr>						
					</tbody>
				</table>
			</form>
		</div>
	</div>
</body>
</html>